import { defineStore } from 'pinia'
import {reactive} from 'vue'

export const useReservationSettingStore = defineStore('reservationSetting', () => {
    const reservationSetting = reactive({
        s1: 0,
        preStartDays: 1,
        s2: 0,
        preEndHours: 2,
        preEndDays: 1,
        preEndTime: '09:30',
        s3: 0,
        preCancelHours: 2,
        preCancelDays: 1,
        preCancelTime: '09:30'
    })

    const setReservationSetting = (setting) => {
        reservationSetting.s1 = setting.s1
        reservationSetting.preStartDays = setting.preStartDays
        reservationSetting.s2 = setting.s2
        reservationSetting.preEndHours = setting.preEndHours
        reservationSetting.preEndDays = setting.preEndDays
        reservationSetting.preEndTime = formatTime(setting.preEndTime)
        reservationSetting.s3 = setting.s3
        reservationSetting.preCancelHours = setting.preCancelHours
        reservationSetting.preCancelDays = setting.preCancelDays
        reservationSetting.preCancelTime = formatTime(setting.preCancelTime)
    } 

    const formatTime = (date) => {
        var hours = date.getHours().toString().padStart(2, '0');
        var minutes = date.getMinutes().toString().padStart(2, '0');
        return hours + ':' + minutes;
    }

    return {
        reservationSetting,
        setReservationSetting
    }
})
